﻿using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Common;
using QxFramework.Core;
using System;
public class PlayerDataManager : LogicModuleBase, IPlayerDataManager
{
    public AllPlayerDatas allPlayerDatas;
    public override void Init()
    {
        base.Init();
        if (!RegisterData(out allPlayerDatas))
        {
            InitAllData();
        }
    }
    private void InitAllData()
    {
        allPlayerDatas = new AllPlayerDatas();
        PlayerData playerData = new PlayerData();
        playerData.PlayerName = "Player-0";
        playerData.CurrentSkillID = 0;
        playerData.PlayerMono = GameMgr.Get<ISpawnManager>().GetInitMonoData("Player0");
        playerData.PlayerID = 0;
        allPlayerDatas.PlayerDatas.Add(playerData);

        if(Data.Instance.PlayersCount == 2)
        {
            PlayerData playerData1 = new PlayerData();
            playerData1.PlayerName = "Player-1";
            playerData1.CurrentSkillID = 0;
            playerData1.PlayerMono = GameMgr.Get<ISpawnManager>().GetInitMonoData("Player1");
            playerData1.PlayerID = 1;
            allPlayerDatas.PlayerDatas.Add(playerData1);
        }
    }

    public AllPlayerDatas GetPlayerDatas()
    {
        return allPlayerDatas;
    }

    public void ChangeSkillID(PlayerData PlayerDatas, bool Next)
    {
        if (PlayerDatas.realTimeStatus.IsChangingSkill)
        {
            return;
        }
        if (Next)
        {
            PlayerDatas.realTimeStatus.IsChangingSkill = true;
            if (PlayerDatas.CurrentSkillID >= PlayerDatas.PlayerMono.SkillList.Count - 1)
            {
                PlayerDatas.CurrentSkillID = 0;
            }
            else
            {
                PlayerDatas.CurrentSkillID += 1;
            }
        }
        else
        {
            PlayerDatas.realTimeStatus.IsChangingSkill = true;
            if (PlayerDatas.CurrentSkillID <= 0)
            {
                PlayerDatas.CurrentSkillID = PlayerDatas.PlayerMono.SkillList.Count - 1;
            }
            else
            {
                PlayerDatas.CurrentSkillID -= 1;
            }
        }
    }
}
public class AllPlayerDatas : GameDataBase
{
    public List<PlayerData> PlayerDatas = new List<PlayerData>();
}
public class PlayerData
{
    public Mono PlayerMono = new Mono();
    public RealTimeStatus realTimeStatus = new RealTimeStatus();
    public int PlayerID = 0;
    public int CurrentSkillID = 0;
    public string PlayerName ="";
    public LevelData PlayerLevelData = new LevelData();
}
public class LevelData
{
    public int CurrentLevel = 0;
    public int CurrentRoomID = 0;
    public int CurrentDifficulty = 0;
    public List<int> EnteredRoom = new List<int>();
}
public class RealTimeStatus
{
    public bool IsChangingSkill =false;
}
